<template>
  <div class="conMain" >
    <el-card  class="box-card" >
      <div slot="header" class="topfix">
          <el-form   :inline="true"  :model="params" size="small" class="goodsForm"  label-width="100px">
              <el-form-item label="ID">
                  <el-input v-model="params.s_id"  placeholder="请输入ID" />
              </el-form-item>
              <el-form-item label="状态">
                  <el-select v-model="params.s_status"  placeholder="请选择">
                   <el-option  :label="item.txt" :value="item.val" v-for="(item,index) in statuslist" />
                  </el-select>
              </el-form-item>
              <el-form-item label=" ">
              <el-button type="primary"  size="small" class="searchBtn" @click="handleSearch" icon='el-icon-search'>搜索</el-button>
              <el-button type="info"  @click="handleRet" plain>重置</el-button>
              </el-form-item>
          </el-form>
          <div style="text-align: right;">
            <el-button  type="primary" size="small" class="ml10" @click="add" plain><i class="el-icon-plus" /> 添加</el-button>
          </div>
      </div>
      <el-table v-loading="loading"  :data="list" style="width: 100%" :empty-text='emtypetxt'>
          <el-table-column prop="id" label="ID" align="center" width="100" />
          <el-table-column prop="days" label="限制天数" align="center"  min-width="80"/>
          <el-table-column prop="num" label="限制单数" align="center"  />
          <el-table-column prop="gids" label="限制商品id集合" align="center"  />
                <el-table-column label="状态" align="center">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.status === 1" type="success" size="mini" disable-transitions>开启</el-tag>
              <el-tag v-if="scope.row.status === -1" type="info" size="mini" disable-transitions>关闭</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="createtime" label="创建时间" align="center" width="200" />
          <el-table-column label="操作" align="center" width="200">
            <template slot-scope="scope" >
                <el-link  :underline="false" type="primary" title='编辑' @click="edit(scope.row.id)">编辑</el-link>
                <el-link  :underline="false" type="danger" title='删除' @click="del(scope.row.id)" class='ml10'>删除</el-link>
            </template>
          </el-table-column>
      </el-table>
      <div class="pagination">
          <el-pagination
            :current-page="params.page"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="params.pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
      </div>
    </el-card>
  </div>
</template>

<script>
import { 
    limit_order_index,
    limit_order_add,
    limit_order_edit,
    limit_order_del,
 } from  '@/api/limit'


export default {
  data() {
    return {
      total:0,
      loading:true,
      emtypetxt:'',
      list: [],
      statuslist:[{val:'1',txt:'开启'},{val:'0',txt:'关闭'}],
      params: {
        s_id:'',
        s_type:'',
        s_status:'',
        page: 1,
        pagesize:10,
      },
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.emtypetxt='加载中...';
      this.loading=true;
      limit_order_index(this.params).then(res => {
        this.list=res.data.list
        this.total=res.data.total
        this.loading = false
        if(this.list.length==0){
          this.emtypetxt='暂无数据'
        }
      })
    },
    handleRet(){
      this.params={
        s_id:'',
        s_status:'',
        page: 1,
      },
      this.list=[];
      this.getList()
    },
    handleSearch(){
      this.list=[];
      this.params.page=1;
      this.getList()
    },
    //分页
    handleSizeChange(val) {
        this.params.pagesize = val
        this.getList()
    },
    handleCurrentChange(val) {
        this.params.page = val
        this.getList()
    },
    add(){
        this.$modalForm(limit_order_add()).then(() => this.getList())
    },
    edit(id) {
        this.$modalForm(limit_order_edit({id:id})).then(() => this.getList())
    },

    del(id) {
      let _this=this;
      _this.$modalSure().then(() => {
        limit_order_del({ids:id}).then(res => {
          _this.$message.success(res.msg)
          _this.getList()
        })
      })
    },
  },
}
</script>

<style lang="scss" scoped>


</style>
